//
//  RHomeViewController.m
//  iMoive
//
//  Created by 侯伟 on 2021/8/24.
//

#import "RHomeViewController.h"
#import "RHomeHotPageViewController.h"
#import "RHomeAllVideoViewController.h"
@interface RHomeViewController (){
    NSArray* _pageInfos;
}

@end

@implementation RHomeViewController

- (instancetype)init{
    if(self = [super init]){
        
        [self initPageInfo];
        
        self.titleColorSelected = COLOR_WHITE;
        self.titleColorNormal = COLOR_WHITE;
        self.titleFontSelected = FONTBOLD(18);
        self.titleFontNormal = FONT(15);
        self.progressColor = COLOR_WHITE;
        self.menuViewStyle = WMMenuViewStyleDefault;
        self.menuItemWidth = SCREEN_WIDTH/_pageInfos.count;
        self.menuViewLayoutMode = WMMenuViewLayoutModeScatter;
        self.preloadPolicy = WMPageControllerPreloadPolicyNeighbour;
        self.showOnNavigationBar = YES;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)initPageInfo{
    NSMutableArray* pages = [NSMutableArray array];
    [pages addObject:@{@"type":@(VideoType_Hot),@"title":@"热门"}];
    [pages addObject:@{@"type":@(VideoType_Movie),@"title":@"电影"}];
    [pages addObject:@{@"type":@(VideoType_TV),@"title":@"电视剧"}];
    [pages addObject:@{@"type":@(VideoType_Variety),@"title":@"综艺"}];
    [pages addObject:@{@"type":@(VideoType_Anime),@"title":@"动漫"}];
    _pageInfos = pages;
}

#pragma mark -- WMPageControllerDataSource

- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return _pageInfos.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    
    NSDictionary* pageInfo = _pageInfos[index];
    return pageInfo[@"title"];
}

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    
    NSDictionary* pageInfo = _pageInfos[index];
    VideoType VideoType = [pageInfo[@"type"] integerValue];
    
    if(VideoType_Hot == VideoType){
        return [RHomeHotPageViewController new];
    }
    
    RHomeAllVideoViewController* subontroller = [RHomeAllVideoViewController new];
    subontroller.VideoType = VideoType;
    return subontroller;
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView {
    return CGRectMake(0, 0, self.view.frame.size.width, 44);
}

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView {
    CGFloat y = 0;
    return CGRectMake(0, y, self.view.frame.size.width, SCREEN_HEIGHT - IPHONE_NAVIGATION_BAR_HEIGHT - IPHONE_TAB_BAR_HEIGHT);
}

@end
